// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var leftMenu = require("../leftMenu/leftMenu");
	var topMenu = require("../topMenu/topMenu");
	var router = require("../hash/pageRouter");
	var footer = require("../footer/footer_main");
	var dialog = require("dialog");
	var validate = require("validate");
	var css_this = require("./staffManageList.css");
	var databind = require("databind");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var imgSrc;
	var init = function(num) {
		leftMenu.init(num);
		topMenu.init(num);
		footer.init();
		$("#footer").removeClass("none");
		$(".table-section").removeClass("none");
		$(".footer").removeClass("none");
		$("#leftMenu3").find(".leftMenu-item").removeClass("leftMenu-active");
		$("#leftMenu3 #staffManageList").parent(".leftMenu-item").addClass("leftMenu-active");
		$("#leftMenu3 .leftMenu li:first-child").addClass("leftMenu-open");
		initEvent();
		inquireLogisticsClerkPageList();
		router.init();
	};
	var initEvent = function() {
		//		$(".page-content-main").on("click",".handle-type",function(){
		//			router.route("newTaskList/newTaskDetail.html");
		//		});
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		/*新增的点击事件*/

		$("#leftMenu3").on("click", "#undoneTaskList", function() {
			router.route("staffManageList/undoneTaskList.html");
		});
		//点击搜索按钮
		$(".search-item-button").on("click", function() {
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化			
			inquireLogisticsClerkPageList();

		});

		//点击添加人员按钮
		$(".button-submit-addClerk").on("click", function() {
			var addClerkDialog = $("#addClerkDialog");
			dialog.showDialog(addClerkDialog, function() {});
			$(".dialogBtn").on("click", function() {

				var promptString = validate.isPhone($("#clerkMobile"));
				if (promptString != "") {
					base.alert(2, promptString);
				} else {
					databind.submitDom(".dialogContent", function() {
						base.alert(1, "添加人员成功");
						inquireLogisticsClerkPageList();
						dialog.dialogClear($("#addClerkDialog"));
					});
				}

			});

		});

		//点击删除
		$("#logisticsClerkBody").on("click", ".handle-delete", function() {
			var clerkId = [];
			var $this = $(this).parents("tr.tr_style");
			clerkId.push($this.attr("clerkId"));
			dialog.showConfirmDialog("删除物流人员", "确定删除此物流人员吗？", function() {
				base.fnAjax({
					action: "disableLogisticsClerk.json",
					oData: {
						clerkId: clerkId
					}, //传递参数
					fnSuccess: function(data) {
						if (data.status == 200) {
							base.alert(1, "删除人员成功");
							top.location.href = "../staffManageList/staffManageList.html";
						} else {
							base.alert(2, "信息获取失败");
						}
					}
				});
			});
		});

		//点击重置密码
		$("#logisticsClerkBody").on("click", ".handle-reset", function() {
			var clerkId = [];
			var $this = $(this).parents("tr.tr_style");
			clerkId.push($this.attr("clerkId"));
			dialog.showConfirmDialog("重置密码", "确定重置此物流人员密码吗？", function() {
				base.fnAjax({
					action: "retrieveLogisticsResetPasswordUuid.json",
					oData: {
						clerkId: clerkId
					}, //传递参数
					fnSuccess: function(data) {
						if (data.status == 200) {
							inquireLogisticsClerkPageList();
							base.alert(1, "密码重置成功");

						} else {
							base.alert(2, "信息获取失败");
						}
					}
				});
			});
		});

	};
	//查询人员列表
	var inquireLogisticsClerkPageList = function() {
		var body = base.parseForm($(".page-content-search"));
		base.fnAjax({
			action: "inquireLogisticsClerkPageList.json",
			oData: {
				pageIndex: pageIndex,
				pageSize: pageSize,
				clerkMobile: body.clerkMobile,
				clerkName: body.clerkName
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#logisticsClerkListTpl").html();
					var html = juicer(tpl, data);
					$("#logisticsClerkBody").html(html);
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl(
						$("#pagenation"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;
							inquireLogisticsClerkPageList();
						});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	return {
		init: init
	};
});